import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
 * 计数器的应用
 */
class CounterDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      title: 'Flutter Demo',
      //是否显示debug标签
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.yellow,
      ),
      home: MyCounterDemo('计数器的应用'),
    );
  }
}

class MyCounterDemo extends StatefulWidget {
  late final String title;
  @override
  State<StatefulWidget> createState() => MyCounterState();

  MyCounterDemo(this.title);
}

class MyCounterState extends State<MyCounterDemo> {
  int _counter = 0;

  void _initcreateCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              '点击右下角按钮增加计数',
              style: TextStyle(
                fontSize: 25,
                color: Colors.black,
              ),
            ),
            Text(
              '$_counter',
              style: TextStyle(fontSize: 25, color: Colors.black),
            ),
          ],
        ),
      ),
      //按钮
      floatingActionButton: FloatingActionButton(
        onPressed: _initcreateCounter,
        child: Icon(Icons.add),
      ),
    );
  }
}
